<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>API测试页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            padding: 20px;
            max-width: 600px;
            margin: 0 auto;
        }
        button {
            padding: 10px 20px;
            margin: 10px 5px;
            font-size: 16px;
        }
        #result {
            margin-top: 20px;
            padding: 15px;
            background: #f0f0f0;
            border-radius: 5px;
            white-space: pre-wrap;
            word-break: break-all;
        }
        .success { background: #d4edda; color: #155724; }
        .error { background: #f8d7da; color: #721c24; }
    </style>
</head>
<body>
    <h1>记账本API测试</h1>
    <p>当前页面URL: <span id="url"></span></p>
    
    <button onclick="testCategories()">测试分类API</button>
    <button onclick="testTransactions()">测试交易API</button>
    <button onclick="testStatistics()">测试统计API</button>
    
    <div id="result"></div>

    <script>
        document.getElementById('url').textContent = window.location.href;
        
        function showResult(title, data, isError = false) {
            const result = document.getElementById('result');
            result.className = isError ? 'error' : 'success';
            result.innerHTML = `<strong>${title}</strong>\n\n${JSON.stringify(data, null, 2)}`;
        }
        
        async function testCategories() {
            try {
                showResult('正在请求...', {message: '请求分类数据中...'});
                const response = await fetch('http://10.42.0.1:3000/api/categories');
                const data = await response.json();
                showResult('✅ 分类API测试成功', data);
            } catch (error) {
                showResult('❌ 分类API测试失败', {
                    error: error.message,
                    stack: error.stack
                }, true);
            }
        }
        
        async function testTransactions() {
            try {
                showResult('正在请求...', {message: '请求交易数据中...'});
                const response = await fetch('http://10.42.0.1:3000/api/transactions');
                const data = await response.json();
                showResult('✅ 交易API测试成功', data);
            } catch (error) {
                showResult('❌ 交易API测试失败', {
                    error: error.message,
                    stack: error.stack
                }, true);
            }
        }
        
        async function testStatistics() {
            try {
                showResult('正在请求...', {message: '请求统计数据中...'});
                const response = await fetch('http://10.42.0.1:3000/api/statistics/overview');
                const data = await response.json();
                showResult('✅ 统计API测试成功', data);
            } catch (error) {
                showResult('❌ 统计API测试失败', {
                    error: error.message,
                    stack: error.stack
                }, true);
            }
        }
    </script>
</body>
</html>

